package com.java.huxb.web.service;

import org.springframework.stereotype.Service;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author huxb
 * @date 2020/4/10 0010 上午 11:04
 */
@Service
public class IndexService {

    private static Lock lock = new ReentrantLock();

    public void testIndex() {
        System.out.println("ThreadName" + Thread.currentThread().getName());
        lock.lock();
        try {
            for (int i = 0; i < 20; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(i);
            }
        } finally {
            lock.unlock();
        }

    }
}
